<?php
/**
 * Created by PhpStorm.
 * User: Yu bo
 * Date: 2018-05-10
 * Time: 17:54
 */
namespace plugins\notice;
use app\common\controller\Plugin;
use think\Db;
/**
 *公告管理插件
 *@author Frank Yu
 *@date 2018-05-10
 */

class index extends Plugin
{
    public $hooks = [
    'Notice',
    ];
    public function install(){
        return true;
    }

    public function uninstall(){
        //删除钩子
        return true;
    }

    public function Notice()
    {
        $data = Db::query('
          SELECT * FROM xue_posts WHERE id in
(
 SELECT object_id FROM xue_term_relationships WHERE term_id =
 (
   SELECT term_id FROM xue_terms WHERE name="学院公告"
 )
)
ORDER BY create_time DESC
        ');
        $data_first = Db::query('
        SELECT * FROM xue_posts WHERE id in
    (
        SELECT object_id FROM xue_term_relationships WHERE term_id =
        (
        SELECT term_id FROM xue_terms WHERE name="学院公告"
 )
)
ORDER BY create_time DESC LIMIT 1
        ');
        $data = json_encode($data);
        $data_first = json_encode($data_first);
        $this->assign('data',$data);
        $this->assign('data_first',$data_first);
        return $this->fetch('notice_list');
    }
}